***cleaning AJD2  ***** 
****lady lawyers project, 2024

clear 
set more off 

set scheme lean2
*set scheme swift_red
graph set window fontface "Arial Narrow"

cd "$Data"

global tt1 cells(b(star fmt(%-9.3f)) se(fmt(%-9.3f) par( [ ] )) blank) stats (r2 N, fmt(%9.2f %9.0g)) style(fixed) starlevel("*" 0.10 "**" 0.05 "***" 0.01)

use "$Data\33584-0001-Data.dta" 
do "$Data\33584-0001-Supplemental_syntax.do"

cd "$Data"

**** cleaning **** 

gen gender =  0
replace gender = 1 if BQ076 == 2
gen age = 0
replace age = 1 if BQ079_BRAC == 5
replace age = 2 if BQ079_BRAC == 4
replace age = 3 if BQ079_BRAC == 3
replace age = 4 if BQ079_BRAC == 2
replace age = 5 if BQ079_BRAC == 1

gen debt_at_graduation = BQ067A_ALL

gen white = 0
replace white = 1 if BQ077E == 1
gen pid = .
replace pid =1 if BQ073 == 1
replace pid = 2 if BQ073 ==2
replace pid = 3 if BQ073 == 3
replace pid = 2 if BQ073 == 4

gen income_bracket = BQ095A_BRAC

gen ideo_social = BQ074A 
gen ideo_econ = BQ074B

gen married = 0
replace married = 1 if inrange(BQ086, 2,4)
replace married = . if BQ086 == .


gen any_children = BQ090A 
recode any_children 9=.
gen n_children = BQ090B
recode n_children 9=.


gen consider_politics = .
replace consider_politics = 1 if BQ061E == 1
replace consider_politics = 0 if BQ061E == 0


foreach var of varlist BQ075A BQ075B BQ075C BQ075D BQ075E BQ075F BQ075G BQ075H BQ075I BQ075J BQ075K BQ075L BQ075M BQ075N BQ075O BQ075P BQ075Q {
	gen `var'2 = 0
	replace `var'2 = 1 if `var' == 1
	recode `var' 2=1
}
egen participation_all = rowtotal (BQ075A BQ075B BQ075C BQ075D BQ075E BQ075F BQ075G BQ075H BQ075I BQ075J BQ075K BQ075L BQ075M BQ075N BQ075O BQ075P BQ075Q)

egen lead_all = rowtotal (BQ075A2 BQ075B2 BQ075C2 BQ075D2 BQ075E2 BQ075F2 BQ075G2 BQ075H2 BQ075I2 BQ075J2 BQ075K2 BQ075L2 BQ075M2 BQ075N2 BQ075O2 BQ075P2 BQ075Q2)

gen participation_gender = BQ075K
gen lead_gender = BQ075K2
gen participation_civic = BQ075M
gen lead_civic = BQ075M2
gen participation_polparty = BQ075A
gen lead_polparty = BQ075A2
gen participation_poladvoc = BQ075B
gen lead_poladvoc = BQ075B2
gen participation_pta = BQ075C
gen lead_pta = BQ075C


egen agentic_goals = rowmean(BQ048A BQ048C BQ048D)

rename BQ048A ag_intellectual_challenge
rename BQ048C ag_wealth
rename BQ048D ag_influencial_person 

egen communal_goals = rowmean(BQ048B BQ048E BQ048F BQ048G)

egen agentic_workplace = rowmean(BQ052A BQ052C BQ052F BQ052J) 
egen communal_workplace = rowmean(BQ052B BQ052D BQ052E BQ052G BQ052K BQ052L BQ052M)

egen agentic_satisfaction = rowmean(BQ043A BQ043B BQ043E)
egen communal_satisfaction = rowmean(BQ043I BQ043J BQ043N BQ043P)

foreach var of varlist agentic_workplace communal_workplace agentic_goals communal_goals agentic_satisfaction communal_satisfaction ag_*{
	sum `var'
	gen `var'_scale = (`var' -`r(min)') / (`r(max)'-`r(min)')
}


egen discrim_all = rowmean(BQ045A BQ045B BQ045C BQ045D BQ045D)
rename BQ045A discrim_comment
rename BQ045B discrim_assign
rename BQ045C discrim_client
rename BQ045D discrim_colleague
rename BQ045E discrim_other

gen communal_employment = 0
gen govt_employment = 0
replace communal_employment = 1 if inrange(BQ004,5,7) 
replace govt_employment = 1 if BQ004 == 2 | BQ004 == 3
foreach var of varlist  BQ050A2 BQ050B2 BQ050C2 BQ050D2 BQ050E2 {
	replace communal_employment = 1 if `var'==4 
	replace communal_employment = 1 if `var'==6
	replace communal_employment = 1 if `var'==7 
	replace govt_employment = 1 if `var' == 2
	replace govt_employment = 1 if `var' == 3
}

gen law_rank = ALSRANK4A

gen per_work_male= BQ021 

gen pro_bono_work = BQ019A 
	sum pro_bono_work
	gen pro_bono_work_scale = (pro_bono_work -`r(min)') / (`r(max)'-`r(min)')

*** labeling variables *** 

label var gender "Gender"
label define gender 0 "women" 1 "men"

label var pid "Party ID"
label define pid 1 "Democrat" 2 "Independent" 3 "Republican"
label var ideo_social "Social policy ideology"
label var ideo_econ "Economic policy ideology"

label var any_children "Any minor children"
label var n_children "Number of minor children"

label var married "Married or partnered"

label var age "Age"
label define age 1 "35 and under" 2 "36-37" 3 "38-39" 4 "40-45" 5 "45+"

label var law_rank "Law school ranking"
label var consider_politics "Considered politics as alternative to law"

label var communal_employment "Works or worked in non-profit or public interest law"
label var govt_employment "Works or worked in govt"

label var per_work_male "% of workplace who are men"
label var pro_bono_work "Pro-bono hours at work"
label var pro_bono_work_scale "Pro-bono hours, scaled"

label var agentic_workplace_scale "Agentic reasons for picking workplace"
label var communal_workplace_scale "Communal reasons for picking workplace"
label var agentic_satisfaction_scale "Agentic satisfaction w work"
label var communal_satisfaction_scale "Communal satisfaction w work"
label var agentic_goals_scale "Agentic career goals"
label var communal_goals_scale "Communal career goals"


*** saving 

save "$Data\ajd2_cleaned.dta", replace 

keep ASU_ID age agentic_goals agentic_goals_scale agentic_satisfaction agentic_satisfaction_scale agentic_workplace agentic_workplace_scale any_children communal_employment communal_goals communal_goals_scale communal_satisfaction communal_satisfaction_scale communal_workplace communal_workplace_scale consider_politics debt_at_graduation discrim_all discrim_assign discrim_client discrim_colleague discrim_comment discrim_other gender govt_employment ideo_econ ideo_social income_bracket law_rank lead_all lead_civic lead_gender lead_poladvoc lead_polparty lead_pta married n_children participation_all participation_civic participation_gender participation_poladvoc participation_polparty participation_pta per_work_male pid pro_bono_work pro_bono_work_scale white ag_*

foreach var of varlist age agentic_goals agentic_goals_scale agentic_satisfaction agentic_satisfaction_scale agentic_workplace agentic_workplace_scale any_children communal_employment communal_goals communal_goals_scale communal_satisfaction communal_satisfaction_scale communal_workplace communal_workplace_scale consider_politics debt_at_graduation discrim_all discrim_assign discrim_client discrim_colleague discrim_comment discrim_other gender govt_employment ideo_econ ideo_social income_bracket law_rank lead_all lead_civic lead_gender lead_poladvoc lead_polparty lead_pta married n_children participation_all participation_civic participation_gender participation_poladvoc participation_polparty participation_pta per_work_male pid pro_bono_work pro_bono_work_scale white {
	rename `var' `var'w2
}

gen wave = 2
gen year = 2010

save "$Data\ajd2_reduced.dta", replace